package clientGUI.userPanels.Controllers;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JTextPane;

import clientserver.AttachedFile;
import clientserver.Client;
import clientserver.Packet;
import clientserver.QueryResult;
import college.Request;
import college.RequestTreatment;

public class EvaluatorPanelController 
{
	Client client;
	int rid;
	ArrayList<String> afiles;
	RequestTreatment r;

	
	public EvaluatorPanelController(int id,Client cl)
	{
	    client = cl;
	    rid = id;
	    afiles= new ArrayList<String>();
		
	}


 public String getRequestInfo()
	 
	 {
		 Request req= new  Request(client);
		 req.loadFromDb(rid);
		 return req.toString();
		 
		 
	 }	

	public void submitDatetoR(String s) 
	{
		r = new RequestTreatment(client,rid);
		r.setcurrentstage(4);
		r.updatestageindb();
		String q;
		q = "Update Request_details r Set r.end_date = '"+s+"' Where r.id = '"+rid+"'" ;
		Packet p=new Packet(q);
		 p.setUpdatePacket();
		 client.SendPacketNowait(p);
		
		
	}

	
 public  ArrayList<String>  getAttachedFiles()
 
 {
	 String q=" SELECT * FROM  attachedfiles WHERE rid="+rid;
	 
	 Packet p=new Packet(q);
	QueryResult qr = (QueryResult) client.SendPacketAndWait(p);
	
	do
	{
	 String fn=qr.getString("filename");
	 afiles.add(fn);
	 
	}while(qr.next());
	

	 return afiles;
	 
 }
public void  openFileInWindows(String fname) throws IOException
{

	AttachedFile  f= new AttachedFile(false);
	f.setRid(rid);
	
	f.setFilename(fname);
	

		AttachedFile fl= client.GetFile(f);
		
fl.clientside();
fl.savefile();
File file= new File(fl.gettempfullpath());
	Desktop.getDesktop().open( file );	


	
}
}
